package com.ruoyi.asset.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AstStoreroom;
import com.ruoyi.asset.service.IAstStoreroomService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;

/**
 * 库房管理Controller
 * 
 * @author xunzhe
 * @date 2024-06-17
 */
@Controller
@RequestMapping("/asset/astStoreroom")
public class AstStoreroomController extends BaseController
{
    private String prefix = "asset/astStoreroom";

    @Autowired
    private IAstStoreroomService astStoreroomService;

    @RequiresPermissions("asset:astStoreroom:view")
    @GetMapping()
    public String astStoreroom()
    {
        return prefix + "/astStoreroom";
    }

    /**
     * 查询库房管理树列表
     */
    @RequiresPermissions("asset:astStoreroom:list")
    @PostMapping("/list")
    @ResponseBody
    public List<AstStoreroom> list(AstStoreroom astStoreroom)
    {
        List<AstStoreroom> list = astStoreroomService.selectAstStoreroomList(astStoreroom);
        return list;
    }

    /**
     * 导出库房管理列表
     */
    @RequiresPermissions("asset:astStoreroom:export")
    @Log(title = "库房管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AstStoreroom astStoreroom)
    {
        List<AstStoreroom> list = astStoreroomService.selectAstStoreroomList(astStoreroom);
        ExcelUtil<AstStoreroom> util = new ExcelUtil<AstStoreroom>(AstStoreroom.class);
        return util.exportExcel(list, "库房管理数据");
    }

    /**
     * 新增库房管理
     */
    @GetMapping(value = { "/add/{storeroomId}", "/add/" })
    public String add(@PathVariable(value = "storeroomId", required = false) Long storeroomId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(storeroomId))
        {
            mmap.put("astStoreroom", astStoreroomService.selectAstStoreroomByStoreroomId(storeroomId));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存库房管理
     */
    @RequiresPermissions("asset:astStoreroom:add")
    @Log(title = "库房管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AstStoreroom astStoreroom)
    {
        return toAjax(astStoreroomService.insertAstStoreroom(astStoreroom));
    }

    /**
     * 修改库房管理
     */
    @RequiresPermissions("asset:astStoreroom:edit")
    @GetMapping("/edit/{storeroomId}")
    public String edit(@PathVariable("storeroomId") Long storeroomId, ModelMap mmap)
    {
        AstStoreroom astStoreroom = astStoreroomService.selectAstStoreroomByStoreroomId(storeroomId);
        mmap.put("astStoreroom", astStoreroom);
        return prefix + "/edit";
    }

    /**
     * 修改保存库房管理
     */
    @RequiresPermissions("asset:astStoreroom:edit")
    @Log(title = "库房管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AstStoreroom astStoreroom)
    {
        return toAjax(astStoreroomService.updateAstStoreroom(astStoreroom));
    }

    /**
     * 删除
     */
    @RequiresPermissions("asset:astStoreroom:remove")
    @Log(title = "库房管理", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{storeroomId}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("storeroomId") Long storeroomId)
    {
        return toAjax(astStoreroomService.deleteAstStoreroomByStoreroomId(storeroomId));
    }

    /**
     * 选择库房管理树
     */
    @GetMapping(value = { "/selectAstStoreroomTree/{storeroomId}", "/selectAstStoreroomTree/" })
    public String selectAstStoreroomTree(@PathVariable(value = "storeroomId", required = false) Long storeroomId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(storeroomId))
        {
            mmap.put("astStoreroom", astStoreroomService.selectAstStoreroomByStoreroomId(storeroomId));
        }
        return prefix + "/tree";
    }

    /**
     * 加载库房管理树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = astStoreroomService.selectAstStoreroomTree();
        return ztrees;
    }
}
